package com.ruoyi.web.controller.cs;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.utils.poi.Excel2Util;
import com.ruoyi.cs.domain.TBoxTitle;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.TExchange;
import com.ruoyi.cs.service.ITExchangeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户兑换记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Api(tags = {"用户兑换记录"})
@RestController
@RequestMapping("/cs/exchange")
public class TExchangeController extends BasicsController
{
    @Autowired
    private ITExchangeService tExchangeService;

    /**
     * 查询用户兑换记录列表
     */
    @ApiOperation("查询用户兑换记录列表")
    @RequestMapping(name="查询用户兑换记录列表",value="list",method = RequestMethod.POST)
    //@PreAuthorize("@ss.hasPermi('cs:exchange:list')")
    public ResponsePageInfo<TExchange> list(@RequestBody  TExchange tExchange)
    {
        startPage(tExchange.getPageNum(),tExchange.getPageSize());
        tExchange.setDelFlag(Constants.SUCCESS);
        List<TExchange> list = tExchangeService.selectTExchangeList(tExchange);
        return toResponsePageInfo(list);
    }
    /**
     * 后台查询用户兑换记录列表
     */
    @ApiOperation("后台查询用户兑换记录列表")
    @RequestMapping(name="后台查询用户兑换记录列表",value="listBack",method = RequestMethod.POST)
    //@PreAuthorize("@ss.hasPermi('cs:exchange:listBack')")
    public ResponsePageInfo<TExchange> listBack(@RequestBody TExchange tExchange)
    {
        startPage(tExchange.getPageNum(),tExchange.getPageSize());
        tExchange.setBackStage(Constants.BACKSTAGE);
        List<TExchange> list = tExchangeService.selectTExchangeList(tExchange);
        return toResponsePageInfo(list);
    }

    /**
     * 导出用户兑换记录列表
     */
    @ApiOperation("导出用户兑换记录列表")
    @PreAuthorize("@ss.hasPermi('cs:exchange:export')")
    @Log(title = "用户兑换记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Response<String> export(TExchange tExchange)
    {
        List<TExchange> list = tExchangeService.selectTExchangeList(tExchange);
        Excel2Util<TExchange> util = new Excel2Util<TExchange>(TExchange.class);
        return util.exportExcel(list, "exchange");
    }

    /**
     * 获取用户兑换记录详细信息
     */
    @ApiOperation("获取用户兑换记录详细信息")
    @PreAuthorize("@ss.hasPermi('cs:exchange:query')")
    @GetMapping(value = "/{dhId}")
    public Response<TExchange> getInfo(
            @ApiParam(name = "dhId", value = "用户兑换记录ID", required = true)
            @PathVariable("dhId") String dhId)
    {
        return Response.success(tExchangeService.selectTExchangeById(dhId));
    }

    /**
     * 新增用户兑换记录
     */
    @ApiOperation("新增用户兑换记录")
    @PreAuthorize("@ss.hasPermi('cs:exchange:add')")
    @Log(title = "用户兑换记录", businessType = BusinessType.INSERT)
    @PostMapping
    public Response<Integer> add(@RequestBody TExchange tExchange)
    {
        return toResponse(tExchangeService.insertTExchange(tExchange));
    }

    /**
     * 修改用户兑换记录
     */
    @ApiOperation("修改用户兑换记录")
    @PreAuthorize("@ss.hasPermi('cs:exchange:edit')")
    @Log(title = "用户兑换记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public Response<Integer> edit(@RequestBody TExchange tExchange)
    {
        return toResponse(tExchangeService.updateTExchange(tExchange));
    }

    /**
     * 删除用户兑换记录
     */
    @ApiOperation("删除用户兑换记录")
    @PreAuthorize("@ss.hasPermi('cs:exchange:remove')")
    @Log(title = "用户兑换记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dhIds}")
    public Response<Integer> remove(
            @ApiParam(name = "dhIds", value = "需要删除的用户兑换记录ID", required = true)
            @PathVariable String[] dhIds)
    {
        return toResponse(tExchangeService.deleteTExchangeByIds(dhIds));
    }

}
